home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_003 / cforth / prims.h < prev    next >
Text File  |  1992-05-06  |  3KB  |  70 lines

  1. /* prims.h: This file defines inline primitives, which are called as functions
  2.    from the big SWITCH in forth.c */
  3.  
  4.                  /* push mem[ip] to cstack */
  5. #define lit() { push (mem[ip++]); }
  6.             /* add an offset (this word) to ip */
  7. #define branch() { ip += mem[ip]; }
  8.             /* return a key from input */
  9. #define key() { push(pkey()); }
  10.         /* return TRUE if break key pressed */
  11. #define qterminal() { pqterm(); }
  12.                 /* and: a b -- a & b */
  13. #define and() { push (pop() & pop()); }
  14.                 /* or: a b -- a | b */
  15. #define or() { push (pop() | pop()); }
  16.                 /* xor: a b -- a ^ b */
  17. #define xor() { push (pop() ^ pop()); }
  18.             /* sp@: push the stack pointer */
  19. #define spfetch() { push (csp); }
  20.             /* sp!: load initial value into SP */
  21. #define spstore() { csp = mem[S0]; }
  22.             /* rp@: fetch the return stack pointer */
  23. #define rpfetch() { push (rsp); }
  24.             /* rp!: load initial value into RP */
  25. #define rpstore() { rsp = mem[R0]; }
  26.             /* ;S: ends a colon definition. */
  27. #define semis() { ip = rpop(); }
  28.             /* @: addr -- mem[addr] */
  29. #define fetch() { push (mem[pop()]); }
  30.             /* C@: addr -- mem[addr] */
  31. #define cfetch() { push (mem[pop()] & 0xff); }
  32.             /* push to return stack */
  33. #define tor() { rpush(pop()); }
  34.             /* pop from return stack */
  35. #define fromr() { push (rpop()); }
  36.             /* 0=: a -- (a == 0) */
  37. #define zeq() { push ( pop() == 0 ); }
  38.             /* 0<: a -- (a < 0) */
  39. #define zless() { push ( pop() < 0 ); }
  40.             /* +: a b -- (a+b) */
  41. #define plus() { push (pop () + pop ()); }
  42.             /* MINUS: negate a number */
  43. #define minus() { push (-pop()); }
  44.                 /* drop: a -- */
  45. #define drop() { pop(); }
  46.             /* DOCOL: push ip & start a thread */
  47. #define docol() { rpush(ip); ip = w+1; }
  48.             /* do a constant: push the value at mem[w+1] */
  49. #define docon() { push (mem[w+1]); }
  50.             /* do a variable: push (w+1) (the PFA) to the stack */
  51. #define dovar() { push (w+1); }
  52.         /* execute a user variable: add UP to the offset found in PF */
  53. #define douse() { push (mem[w+1] + ORIGIN); }
  54.  
  55. #define allot() { Callot (pop()); }
  56.                 /* comparison tests */
  57. #define equal() { push(pop() == pop()); }
  58.                 /* not equal */
  59. #define noteq() { push (pop() != pop()); }
  60.                 /* DODOES -- not supported */
  61. #define dodoes() { errexit("DOES> is not supported."); }
  62.                 /* DOVOC -- not supported */
  63. #define dovoc() { errexit("VOCABULARIES are not supported."); }
  64.                 /* (BYE) -- exit with error code */
  65. #define pbye() { exit(0); }
  66.                 /* TRON -- trace at pop() depth */
  67. #define tron() { trace = TRUE; tracedepth = pop(); }
  68.                 /* TROFF -- stop tracing */
  69. #define troff() { trace = 0; }
  70.